package com.biblio.utils;

import java.security.MessageDigest;

import org.apache.commons.codec.binary.Hex;

public class SecurityUtils {
	public static String md5Encode(String credentials) {
		return encode(credentials, "md5");
	}

	private static String encode(String credentials, String mode) {

		try {
			// Obtain a new message digest with md5 encryption
			MessageDigest md = (MessageDigest) MessageDigest.getInstance(mode)
					.clone();
			// encode the password
			md.update(credentials.getBytes());
			// Digest the credentials and return as hexadecimal
			return new String(Hex.encodeHex(md.digest()));
		} catch (Exception ex) {
			throw new RuntimeException("Could not encode credentials", ex);
		}
	}
}
